package com.getsendsocial.GetSendSocial.Database;


import android.content.Context;
import android.database.Cursor;
import android.os.AsyncTask;

	
public class GetString extends AsyncTask<String, Void, String> {
	
		private Context context;
		private GSDatabase db;
		    	
    	public GetString(Context c){
    		context = c;
    	}    		
    	
    	
    	
		@Override
		protected String doInBackground(String...arg0) {
			
			String frase = null;
			db = new GSDatabase(context);
			db.open();  //apriamo il db
			
			Cursor cursor = db.fetchProducts(arg0[0]);
			if (cursor.getCount()==0){
				db.setFlag(arg0[0]);
				cursor = db.fetchProducts(arg0[0]);
			}
			while (cursor.moveToNext()){
				frase = cursor.getString(cursor.getColumnIndexOrThrow("FRASE"));
				int id = cursor.getInt(cursor.getColumnIndexOrThrow("ID"));
				
				db.changeFlag(id, arg0[0]);
			}
			cursor.close();
			db.close();

			return frase;
		}

	}
	
    	

